/*************************************************************************
	> File Name: oj-xxx.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年11月15日 星期日 20时48分14秒
 ************************************************************************/

#include <iostream>
#include <queue>
int n, mmap[50][50];
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
struct node {
    int x, y, step;
};

using namespace std;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cin >> mmap[i][j];
        }
    }
    queue<node> que;
    que.push((node){0, 0});
    mmap[0][0] = 3;
    while (!que.empty()) {
        node temp = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int x = temp.x + dir[i][0];
            int y = temp.y + dir[i][1];
            if (x < 0 || y < 0 || x > n + 1 || y > n + 1 || mmap[x][y] == 3) {
                continue;
            }
            if (mmap[x][y] == 0) {
                mmap[x][y] = 3;
                que.push((node){x, y});
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (j != 1) cout << " ";
            if (mmap[i][j] == 3) cout << 0;
            else if (mmap[i][j] == 0) cout << 2;
            else cout << 1;
        }
        cout << endl;
    }
    return 0;
}
